﻿using System;
using System.Collections.Generic;
using System.Linq;
using UniRx;
using UniRx.Triggers;
using UnityEngine;

namespace Studio
{
	// Token: 0x020004BF RID: 1215
	public class GuideObject : MonoBehaviour
	{
		// Token: 0x17000374 RID: 884
		// (get) Token: 0x06001EDB RID: 7899 RVA: 0x000C1468 File Offset: 0x000BF668
		// (set) Token: 0x06001EDC RID: 7900 RVA: 0x000C1470 File Offset: 0x000BF670
		public int dicKey
		{
			get
			{
				return this.m_DicKey;
			}
			set
			{
				if (Utility.SetStruct<int>(ref this.m_DicKey, value))
				{
					this.changeAmount = Studio.GetChangeAmount(this.m_DicKey);
				}
			}
		}

		// Token: 0x17000375 RID: 885
		// (get) Token: 0x06001EDD RID: 7901 RVA: 0x000C1494 File Offset: 0x000BF694
		// (set) Token: 0x06001EDE RID: 7902 RVA: 0x000C149C File Offset: 0x000BF69C
		public ChangeAmount changeAmount
		{
			get
			{
				return this.m_ChangeAmount;
			}
			private set
			{
				this.m_ChangeAmount = value;
				if (this.m_ChangeAmount != null)
				{
					ChangeAmount changeAmount = this.m_ChangeAmount;
					changeAmount.onChangePos = (Action)Delegate.Combine(changeAmount.onChangePos, new Action(this.CalcPosition));
					ChangeAmount changeAmount2 = this.m_ChangeAmount;
					changeAmount2.onChangeRot = (Action)Delegate.Combine(changeAmount2.onChangeRot, new Action(this.CalcRotation));
				}
			}
		}

		// Token: 0x17000376 RID: 886
		// (get) Token: 0x06001EDF RID: 7903 RVA: 0x000C150C File Offset: 0x000BF70C
		public GuideSelect guideSelect
		{
			get
			{
				return this.guide[11] as GuideSelect;
			}
		}

		// Token: 0x17000377 RID: 887
		// (get) Token: 0x06001EE0 RID: 7904 RVA: 0x000C151C File Offset: 0x000BF71C
		public bool[] enables
		{
			get
			{
				return this.m_Enables;
			}
		}

		// Token: 0x17000378 RID: 888
		// (get) Token: 0x06001EE1 RID: 7905 RVA: 0x000C1524 File Offset: 0x000BF724
		// (set) Token: 0x06001EE2 RID: 7906 RVA: 0x000C1530 File Offset: 0x000BF730
		public bool enablePos
		{
			get
			{
				return this.m_Enables[0];
			}
			set
			{
				if (Utility.SetStruct<bool>(ref this.m_Enables[0], value))
				{
					this.roots[0].SetActive(this.isActive && this.m_Enables[0]);
					if (this.m_ChangeAmount != null)
					{
						ChangeAmount changeAmount = this.m_ChangeAmount;
						changeAmount.onChangePos = (Action)Delegate.Remove(changeAmount.onChangePos, new Action(this.CalcPosition));
					}
				}
			}
		}

		// Token: 0x17000379 RID: 889
		// (get) Token: 0x06001EE3 RID: 7907 RVA: 0x000C15AC File Offset: 0x000BF7AC
		// (set) Token: 0x06001EE4 RID: 7908 RVA: 0x000C15B8 File Offset: 0x000BF7B8
		public bool enableRot
		{
			get
			{
				return this.m_Enables[1];
			}
			set
			{
				if (Utility.SetStruct<bool>(ref this.m_Enables[1], value))
				{
					this.roots[1].SetActive(this.isActive && this.m_Enables[1]);
					if (this.m_ChangeAmount != null)
					{
						ChangeAmount changeAmount = this.m_ChangeAmount;
						changeAmount.onChangeRot = (Action)Delegate.Remove(changeAmount.onChangeRot, new Action(this.CalcRotation));
					}
				}
			}
		}

		// Token: 0x1700037A RID: 890
		// (get) Token: 0x06001EE5 RID: 7909 RVA: 0x000C1634 File Offset: 0x000BF834
		// (set) Token: 0x06001EE6 RID: 7910 RVA: 0x000C1640 File Offset: 0x000BF840
		public bool enableScale
		{
			get
			{
				return this.m_Enables[2];
			}
			set
			{
				if (Utility.SetStruct<bool>(ref this.m_Enables[2], value))
				{
					this.roots[2].SetActive(this.isActive && this.m_Enables[2]);
				}
			}
		}

		// Token: 0x1700037B RID: 891
		// (get) Token: 0x06001EE7 RID: 7911 RVA: 0x000C167C File Offset: 0x000BF87C
		// (set) Token: 0x06001EE8 RID: 7912 RVA: 0x000C1684 File Offset: 0x000BF884
		public bool calcScale { get; set; }

		// Token: 0x1700037C RID: 892
		// (get) Token: 0x06001EE9 RID: 7913 RVA: 0x000C1690 File Offset: 0x000BF890
		// (set) Token: 0x06001EEA RID: 7914 RVA: 0x000C1698 File Offset: 0x000BF898
		public bool enableMaluti { get; set; }

		// Token: 0x1700037D RID: 893
		// (get) Token: 0x06001EEB RID: 7915 RVA: 0x000C16A4 File Offset: 0x000BF8A4
		// (set) Token: 0x06001EEC RID: 7916 RVA: 0x000C16AC File Offset: 0x000BF8AC
		public bool isActive
		{
			get
			{
				return this.m_IsActive;
			}
			set
			{
				if (Utility.SetStruct<bool>(ref this.m_IsActive, value))
				{
					this.SetMode(GuideObjectManager.GetMode(), true);
				}
			}
		}

		// Token: 0x1700037E RID: 894
		// (get) Token: 0x06001EED RID: 7917 RVA: 0x000C16CC File Offset: 0x000BF8CC
		// (set) Token: 0x06001EEE RID: 7918 RVA: 0x000C16D4 File Offset: 0x000BF8D4
		public float scaleRate
		{
			get
			{
				return this.m_ScaleRate;
			}
			set
			{
				if (Utility.SetStruct<float>(ref this.m_ScaleRate, value))
				{
					this.SetScale();
				}
			}
		}

		// Token: 0x1700037F RID: 895
		// (get) Token: 0x06001EEF RID: 7919 RVA: 0x000C16F0 File Offset: 0x000BF8F0
		// (set) Token: 0x06001EF0 RID: 7920 RVA: 0x000C16F8 File Offset: 0x000BF8F8
		public float scaleRot
		{
			get
			{
				return this.m_ScaleRot;
			}
			set
			{
				if (Utility.SetStruct<float>(ref this.m_ScaleRot, value))
				{
					this.SetScale();
				}
			}
		}

		// Token: 0x17000380 RID: 896
		// (get) Token: 0x06001EF1 RID: 7921 RVA: 0x000C1714 File Offset: 0x000BF914
		// (set) Token: 0x06001EF2 RID: 7922 RVA: 0x000C171C File Offset: 0x000BF91C
		public float scaleSelect
		{
			get
			{
				return this.m_ScaleSelect;
			}
			set
			{
				if (Utility.SetStruct<float>(ref this.m_ScaleSelect, value))
				{
					this.SetScale();
				}
			}
		}

		// Token: 0x17000381 RID: 897
		// (get) Token: 0x06001EF3 RID: 7923 RVA: 0x000C1738 File Offset: 0x000BF938
		public bool isChild
		{
			get
			{
				return this.parentGuide != null;
			}
		}

		// Token: 0x17000382 RID: 898
		// (get) Token: 0x06001EF4 RID: 7924 RVA: 0x000C1748 File Offset: 0x000BF948
		public int layer
		{
			get
			{
				return (!this.isChild) ? base.gameObject.layer : this.parentGuide.gameObject.layer;
			}
		}

		// Token: 0x06001EF5 RID: 7925 RVA: 0x000C1778 File Offset: 0x000BF978
		public void SetMode(int _mode, bool _layer = true)
		{
			for (int i = 0; i < 3; i++)
			{
				if (!(this.roots[i] == null))
				{
					this.roots[i].SetActive(this.isActive && this.m_Enables[i] && _mode == i);
				}
			}
			bool flag;
			if (!this.isActive)
			{
				flag = this.m_Enables.Any((bool b) => b);
			}
			else
			{
				flag = false;
			}
			bool flag2 = flag | (this.isActive && !this.m_Enables[_mode]);
			this.objectSelect.SetActive(flag2);
			if (_layer)
			{
				this.SetLayer(base.gameObject, (!this.isChild) ? LayerMask.NameToLayer((!flag2) ? "Studio/Select" : "Studio/Col") : this.layer);
				if (this.isActiveFunc != null)
				{
					this.isActiveFunc(flag2);
				}
			}
		}

		// Token: 0x06001EF6 RID: 7926 RVA: 0x000C1894 File Offset: 0x000BFA94
		public void SetActive(bool _active, bool _layer = true)
		{
			this.m_IsActive = _active;
			this.SetMode(GuideObjectManager.GetMode(), _layer);
		}

		// Token: 0x17000383 RID: 899
		// (get) Token: 0x06001EF7 RID: 7927 RVA: 0x000C18AC File Offset: 0x000BFAAC
		// (set) Token: 0x06001EF8 RID: 7928 RVA: 0x000C18B4 File Offset: 0x000BFAB4
		public bool visible
		{
			get
			{
				return this.m_Visible;
			}
			set
			{
				if (Utility.SetStruct<bool>(ref this.m_Visible, value))
				{
					for (int i = 0; i < this.guide.Length; i++)
					{
						this.guide[i].draw = this.m_Visible;
					}
				}
			}
		}

		// Token: 0x17000384 RID: 900
		// (get) Token: 0x06001EF9 RID: 7929 RVA: 0x000C1900 File Offset: 0x000BFB00
		// (set) Token: 0x06001EFA RID: 7930 RVA: 0x000C1908 File Offset: 0x000BFB08
		private bool isQuit { get; set; }

		// Token: 0x06001EFB RID: 7931 RVA: 0x000C1914 File Offset: 0x000BFB14
		private void CalcPosition()
		{
			if (this.transformTarget)
			{
				this.transformTarget.localPosition = this.changeAmount.pos;
			}
		}

		// Token: 0x06001EFC RID: 7932 RVA: 0x000C193C File Offset: 0x000BFB3C
		private void CalcRotation()
		{
			if (this.transformTarget)
			{
				this.transformTarget.localRotation = Quaternion.Euler(this.changeAmount.rot);
			}
		}

		// Token: 0x06001EFD RID: 7933 RVA: 0x000C196C File Offset: 0x000BFB6C
		private void CalcScale()
		{
		}

		// Token: 0x06001EFE RID: 7934 RVA: 0x000C1970 File Offset: 0x000BFB70
		public void SetScale()
		{
			this.roots[0].transform.localScale = Vector3.one * this.m_ScaleRate * Studio.optionSystem.manipulateSize;
			this.roots[1].transform.localScale = Vector3.one * 15f * this.m_ScaleRate * 1.1f * this.m_ScaleRot * Studio.optionSystem.manipulateSize;
			this.roots[2].transform.localScale = Vector3.one * this.m_ScaleRate * Studio.optionSystem.manipulateSize;
			this.objectSelect.transform.localScale = Vector3.one * this.m_ScaleRate * this.m_ScaleSelect * Studio.optionSystem.manipulateSize;
		}

		// Token: 0x06001EFF RID: 7935 RVA: 0x000C1A6C File Offset: 0x000BFC6C
		public void SetLayer(GameObject _object, int _layer)
		{
			if (_object == null)
			{
				return;
			}
			_object.layer = _layer;
			Transform transform = _object.transform;
			int childCount = transform.childCount;
			for (int i = 0; i < childCount; i++)
			{
				this.SetLayer(transform.GetChild(i).gameObject, _layer);
			}
		}

		// Token: 0x06001F00 RID: 7936 RVA: 0x000C1AC0 File Offset: 0x000BFCC0
		public void ForceUpdate()
		{
			this.CalcPosition();
			this.CalcRotation();
		}

		// Token: 0x06001F01 RID: 7937 RVA: 0x000C1AD0 File Offset: 0x000BFCD0
		private void Awake()
		{
			this.m_DicKey = -1;
			this.isActiveFunc = null;
			this.parentGuide = null;
			this.enableMaluti = true;
			this.calcScale = true;
			List<GuideBase> list = new List<GuideBase>();
			for (int i = 0; i < 3; i++)
			{
				list.AddRange(this.roots[i].GetComponentsInChildren<GuideBase>().ToList<GuideBase>());
			}
			list.AddRange(this.objectSelect.GetComponentsInChildren<GuideBase>().ToList<GuideBase>());
			this.guide = list.ToArray();
			for (int j = 0; j < this.guide.Length; j++)
			{
				this.guide[j].guideObject = this;
			}
		}

		// Token: 0x06001F02 RID: 7938 RVA: 0x000C1B7C File Offset: 0x000BFD7C
		private void Start()
		{
			this.isQuit = false;
			this.m_Visible = true;
			(from _ in this.OnDestroyAsObservable()
			where !this.isQuit
			where !Scene.isGameEnd
			where Singleton<GuideObjectManager>.IsInstance()
			select _).Subscribe(delegate(Unit _)
			{
				Singleton<GuideObjectManager>.Instance.Delete(this, false);
			}).AddTo(this);
		}

		// Token: 0x06001F03 RID: 7939 RVA: 0x000C1C0C File Offset: 0x000BFE0C
		private void LateUpdate()
		{
			base.transform.position = this.transformTarget.position;
			base.transform.rotation = this.transformTarget.rotation;
			GuideObject.Mode mode = this.mode;
			if (mode != GuideObject.Mode.Local)
			{
				if (mode == GuideObject.Mode.World)
				{
					this.roots[0].transform.eulerAngles = Vector3.zero;
				}
			}
			else
			{
				this.roots[0].transform.eulerAngles = ((!this.parent) ? Vector3.zero : this.parent.eulerAngles);
			}
			if (this.calcScale)
			{
				Vector3 localScale = this.transformTarget.localScale;
				Vector3 lossyScale = this.transformTarget.lossyScale;
				Vector3 vector = (!this.enableScale) ? Vector3.one : this.changeAmount.scale;
				this.transformTarget.localScale = new Vector3(localScale.x / lossyScale.x * vector.x, localScale.y / lossyScale.y * vector.y, localScale.z / lossyScale.z * vector.z);
			}
		}

		// Token: 0x06001F04 RID: 7940 RVA: 0x000C1D50 File Offset: 0x000BFF50
		private void OnApplicationQuit()
		{
			this.isQuit = true;
		}

		// Token: 0x040020D1 RID: 8401
		public Transform transformTarget;

		// Token: 0x040020D2 RID: 8402
		private int m_DicKey = -1;

		// Token: 0x040020D3 RID: 8403
		protected ChangeAmount m_ChangeAmount;

		// Token: 0x040020D4 RID: 8404
		[SerializeField]
		protected GameObject[] roots = new GameObject[3];

		// Token: 0x040020D5 RID: 8405
		[SerializeField]
		protected GameObject objectSelect;

		// Token: 0x040020D6 RID: 8406
		private GuideBase[] guide;

		// Token: 0x040020D7 RID: 8407
		[SerializeField]
		protected bool[] m_Enables = new bool[]
		{
			true,
			true,
			true,
			true
		};

		// Token: 0x040020DA RID: 8410
		public GuideObject.IsActiveFunc isActiveFunc;

		// Token: 0x040020DB RID: 8411
		protected bool m_IsActive;

		// Token: 0x040020DC RID: 8412
		protected float m_ScaleRate = 1f;

		// Token: 0x040020DD RID: 8413
		protected float m_ScaleRot = 1f;

		// Token: 0x040020DE RID: 8414
		protected float m_ScaleSelect = 1f;

		// Token: 0x040020DF RID: 8415
		public GuideObject parentGuide;

		// Token: 0x040020E0 RID: 8416
		protected bool m_Visible = true;

		// Token: 0x040020E1 RID: 8417
		public GuideObject.Mode mode;

		// Token: 0x040020E2 RID: 8418
		public Transform parent;

		// Token: 0x040020E3 RID: 8419
		public GuideObject.Mode calcMode;

		// Token: 0x020004C0 RID: 1216
		// (Invoke) Token: 0x06001F0B RID: 7947
		public delegate void IsActiveFunc(bool _active);

		// Token: 0x020004C1 RID: 1217
		public enum Mode
		{
			// Token: 0x040020E9 RID: 8425
			Local,
			// Token: 0x040020EA RID: 8426
			World
		}
	}
}
